package com.chengqs.rainbow.im.route.util;

import cn.hutool.core.util.StrUtil;
import com.chengqs.rainbow.common.core.constant.SymbolConstants;
import com.chengqs.rainbow.common.core.exception.SystemException;
import com.chengqs.rainbow.common.im.constant.ZkConstants;
import com.chengqs.rainbow.im.route.properties.ConfigProperties;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.net.InetAddress;

/**
 * <B>主类名称：</B>RouteContext<BR>
 * <B>概要说明：</B>enter<BR>
 *
 * @author: chengqs
 * @create: 2025-09-13 17:25:51
 **/
@Component
@RequiredArgsConstructor
public class RouteContext {

    private final ConfigProperties configProperties;

    @Value("${spring.profiles.active}")
    private String profile;

    public String getName() {
        return configProperties.getName();
    }

    public Integer getPort() {
        return configProperties.getPort();
    }

    public String getZkRootPath() {
        return ZkConstants.ZK_ROUTE_PATH + SymbolConstants.FORWARD_SLASH + profile;
    }

    @SneakyThrows
    public String getZkPath() {
        return getZkRootPath()
                + SymbolConstants.FORWARD_SLASH + getName()
                + SymbolConstants.COLON + InetAddress.getLocalHost().getHostAddress()
                + SymbolConstants.COLON + this.getPort();
    }
}
